<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="css/layuimini.css">
    <link rel="stylesheet" href="css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <form id="baseDictSearchForm" class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索方式</label>
                        <div class="layui-input-block">
                            <select id="typeTitle" name="typeTitle">
                                <option value="typeCode">类别编号</option>
                                <option value="typeName">类别名称</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="typeContent" autocomplete="off" class="layui-input"
                                   placeholder="输入类别编号或名称">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <a class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i
                                class="layui-icon"></i> 搜 索</a>
                    </div>
                </div>
            </form>
        </fieldset>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <!--<button class="layui-btn layui-btn-sm data-add-btn"> 添加类别选项</button>-->
                <a href="javascript:;" class="layui-btn layui-btn-sm" data-iframe-tab="baseDictAdd.html"
                   data-title="添加字典类别选项" data-icon="fa fa-gears">添加类别选项</a>
                <!--<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn"> 禁用选项 </button>-->
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">停用</a>
        </script>

    </div>
</div>
<script src="lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<!--tab跳转需要layuimini-->
<script src="js/lay-module/layuimini/layuimini.js" charset="utf-8"></script>

<!--表格数据-->
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        <!--表格-->
        var tableIns = table.render({
            elem: '#currentTableId',
            url: 'getBaseDictList',
            method: 'post',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLETIPS',
                icon: 'layui-icon-tips'
            }],
            request: {
                pageName: 'page', //页码的参数名称，默认：pageNum
                limitName: 'pageSize' //每页数据量的参数名，默认：pageSize
            },
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 0, //成功的状态码，默认：0
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            },
            parseData: function (res) { //res 即为原始返回的数据
                //res.code=0;
                console.log(res);
                return {
                    "code": 0, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.rows //解析数据列表
                };
            },
            cols: [
                [
                    {field: 'id', width: 90, title: 'ID', sort: true},
                    {field: 'typeCode', width: 120, title: '字典编号'},
                    {field: 'typeName', width: 120, title: '字典类别'},
                    {field: 'itemName', width: 150, title: '字典类别选项'},
                    {field: 'dictSort', title: '选项排序编号', width: 120, sort: true},
                    {field: 'dictEnable', width: 150, title: '是否有用'},
                    {field: 'remark', width: 120, title: '备注'},
                    {title: '操作', minWidth: 50, templet: '#currentTableBar', align: "center"}
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            var text = JSON.parse(result);   //{text.custName,custSource。。。}
            console.log(data);
            if (text.typeTitle == "typeCode") { // ===会导致上次输入的数据也被发送
                table.reload('currentTableId', {
                    method: 'post'
                    , where: {
                        typeCode: text.typeContent
                    }  //搜索框里的各个参数,通过这个实现搜索功能，table同一数据接口
                });
            } else {
                table.reload('currentTableId', {
                    method: 'post'
                    , where: {
                        typeName: text.typeContent
                    }  //搜索框里的各个参数,通过这个实现搜索功能，table同一数据接口
                });
            }
            layer.alert(result, {
                title: '最终的搜索信息'
            });
            return false;
        });
        //监听编辑和删除
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑字典',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    resize: false,
                    shadeClose: true,
                    area: ['60%', '90%'],
                    //content: ['customerAdd.html'+ '#custId'+'#custName'],
                    content: 'baseDictAdd.html?edit=1&id=' + data.id //+ '&typeCode='+ data.typeCode
                   // + '&typeName=' + data.typeName + '&itemName=' + data.itemName + '&dictSort=' + data.dictSort + '&remark=' + data.remark

                });
                /* $(window).on("resize", function () {
                     layer.full(index);
                 });*/
                return false;
            } else if (obj.event === 'delete') {
                layer.msg("此功能暂不开放，不能禁用")
            }
        });
        $(".data-add-btn").on("click", function () {

            var index = layer.open({
                title: '添加字典',
                type: 2,
                shade: 0.2,
                maxmin:true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: 'baseDictAdd.html',
            });
            $(window).on("resize", function () {
                layer.full(index);
            });

            return false;
        });
    });
</script>
</body>
</html>
